package cn.adair.oxframe.sample;

import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

import androidx.viewpager.widget.ViewPager;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import cn.adair.oxframe.base.OxBaseActivity;
import cn.adair.oxframe.bean.Titlebean;

public class FragmentActivity extends OxBaseActivity {

    @Override
    public int initLayout() {
        return R.layout.activity_fragment;
    }

    @BindView(R.id.hello)
    TextView hello;
    @BindView(R.id.tab_view)
    ViewPager tab_view;

    private FragmentAdapter fragmentAdapter;
    private List<Titlebean> fragmentTitles;

    @Override
    public void initData(Bundle savedInstanceState) {
        hello.setText("Fragment Hello Oxframe");
        fragmentTitles = new ArrayList<>();
        fragmentTitles.add(new Titlebean("标题A", "TAB_A"));
        fragmentTitles.add(new Titlebean("标题B", "TAB_B"));
        fragmentTitles.add(new Titlebean("标题C", "TAB_C"));
        fragmentAdapter = new FragmentAdapter(getSupportFragmentManager());
        fragmentAdapter.setFragmentTitles(fragmentTitles);
        fragmentAdapter.setFragments(FragmentA.class, FragmentB.class, FragmentC.class);
        tab_view.setAdapter(fragmentAdapter);
        tab_view.setOffscreenPageLimit(fragmentTitles.size());
        tab_view.setCurrentItem(0);
    }

    @OnClick(R.id.tab_a)
    public void tab_a() {
        Toast.makeText(_mContext, "aaaa", Toast.LENGTH_LONG).show();
        tab_view.setCurrentItem(0);
    }

    @OnClick(R.id.tab_b)
    public void tab_b() {
        tab_view.setCurrentItem(1);
    }

    @OnClick(R.id.tab_c)
    public void tab_c() {
        tab_view.setCurrentItem(2);
    }
}
